var pageNow=1;
SPA_RESOLVE_INIT = function(transition) {
    var html = '<table class="Table_common examListTab mt-20">\n' +
        '<thead>\n' +
        '<tr>\n' +
        '<td>id</td>\n' +
        '<td>标题</td>\n' +
        '<td>状态</td>\n' +
        '<td>时间</td>\n' +
        // '<td>类型</td>\n' +
        '<td>操作</td>\n' +
        '</tr>\n' +
        '</thead>\n' +
        '<tbody id="examListTables">\n' +
        '</tbody>\n' +
        '</table> \n' +
        '<div class="paging-area-box mt-10 magin-auto">\n' +
        '<div class="paging-area float-left" id="pagination"></div>\n' +
        '<span class="pageNum float-right f-14">共<em>0</em>条数据</span>\n' +
        '</div>';
    html += '<style>\n' +
        ' \n' +
        ' .examListTab tr td:nth-child(2),\n' +
        ' .examListTab tr td:nth-child(4){\n' +
        'border-left:1px solid #333;\n' +
        'border-right:1px solid #333;\n' +
        '}\n' +
        '.examListTab tr td:nth-child(6){\n' +
        'border-left:1px solid #333;\n' +
        '}\n' +
        '\n' +
        '</style>';
    getHref_path();
    $(".menu ul").hide();
    $(".menu ul").eq(4).show();
    document.getElementById("ui-right-content").innerHTML = html;
    examListFun(pageNow);
}

function examListFun(pageNo){
    var id = window.document.getElementById("examListTables");

    $.ajax({
        url: get_examLlist_interface+'?currentPage='+pageNo,
        type:'post',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            currentPage:pageNo
        },
        success: function(data) {
            if(data.code==200){
                inner_examListTbody(data,id, examListFun);
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function inner_examListTbody(data,id, func){
    var page = data.data.num;
    var currentPage = data.data.currentPage;
    var tml = "";
    $(".pageNum em").html(page);
    if(page>0){
        setPagination(page,currentPage, func);
        pageNow=currentPage;
        var lists = data.data.list;
        $('#pagination').show();
        for (x in lists) {
            tml += "<tr>"+
                "<td>"+lists[x]["exam_id"]+"</td>"+
                "<td>"+lists[x]["exam_name"]+"</td>"+
                "<td>"+lists[x]["state"]+"</td>"+
                "<td>"+lists[x]["start_time"]+" — "+lists[x]["end_time"]+"</td>"+
                '<td>' +
                // '<a href="javascript:;" class="c-009 f-14" onclick="" data-examId="'+lists[x]["exam_id"]+'">成绩</a> / ' +
                '<a href="javascript:;" class="c-009 f-14" onclick="hrefupdate(this)" data-paperId='+lists[x]["paper_id"]+' data-examId="'+lists[x]["exam_id"]+'">编辑</a> / ' +
                '<a href="javascript:;" class="c-009 f-14" onclick="deletes(this)" data-paperId='+lists[x]["paper_id"]+' data-examId="'+lists[x]["exam_id"]+' ">删除</a>' +
                '</td>';
            "</tr>" ;
        }
    }else{
        $('#pagination').hide();
    }
    id.innerHTML = tml;
}

function deletes(obj) {
    deleteExam(obj)
    deletePaper(obj)
}

function deleteExam(obj){
    var examId = $(obj).attr("data-examId");
    $.ajax({
        url: delete_exam_interface,
        type:'post',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            examId:examId
        },
        success: function(data) {
            if(data.code==200){
                $.message("删除成功");
                examListFun(pageNow)
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function deletePaper(obj){
    var paperId = $(obj).attr("data-paperId");
    $.ajax({
        url: delete_paper_interface,
        type:'post',
        dataType:'json',
        xhrFields:{
            withCredentials:true
        },
        crossDomain:true,
        data:{
            paperId:paperId
        },
        success: function(data) {
            if(data.code==200){
            }else{
                $.message(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function hrefupdate(obj) {
    var examId = $(obj).attr("data-examId");
    var paperId = $(obj).attr("data-paperId");
    location.href="?examId="+examId.toString()+"&paperId="+paperId.toString()+"#/updateexam"
}